package com.turnengine.client.global.announcement.command;

import com.javabi.command.IExecutableCommand;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.serializer.AbstractCommandDataSerializer;
import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import java.io.IOException;

/**
 * The Get Announcement Count Data Serializer.
 */
public class GetAnnouncementCountDataSerializer extends AbstractCommandDataSerializer<Integer> implements IGetAnnouncementCountDataSerializer {

	/**
	 * Creates a new Get Announcement Count Data Serializer.
	 */
	public GetAnnouncementCountDataSerializer() {
		super(GetAnnouncementCount.COMMAND_ID);
	}

	@Override
	public Integer readReturnValue(IDataReader reader) throws IOException {
		Integer value = reader.readIntegerObject(true);
		return value;
	}

	@Override
	public void writeReturnValue(IDataWriter writer, Integer value) throws IOException {
		writer.writeIntegerObject(value, true);
	}

	@Override
	public IExecutableCommand<Integer> readRequest(IDataReader reader) throws IOException {

		// Read fields
		int gameId = reader.readInt();

		// Create object
		GetAnnouncementCount object = new GetAnnouncementCount();
		object.setGameId(gameId);
		return object;
	}

	@Override
	public void writeRequest(IDataWriter writer, IExecutableCommand<Integer> argument) throws IOException {
		GetAnnouncementCount object = (GetAnnouncementCount) argument;

		// Get fields
		int gameId = object.getGameId();

		// Write fields
		writer.writeInt(gameId);
	}

	@Override
	public IExecutableCommandResponse<Integer> newResponse() {
		return new GetAnnouncementCountResponse();
	}
}
